﻿using System;
using System.Collections.Generic;

namespace OestsCommon.Model
{

    public class TrainData
    {
        public int StudentId { get; set; }

        public int ProjectId { get; set; }
        /// <summary>
        /// 任务id
        /// </summary>
        public int TaskId { get; set; }

        /// <summary>
        /// 完成时间
        /// </summary>
        public int FinishTime { get; set; }

        public DateTime HandinTime { get; set; }
        /// <summary>
        /// 分值
        /// </summary>
        public int Score { get; set; }


        /// <summary>
        /// 操作记录 任务id 对应任务的记录
        /// </summary>
        public List<string> OperationLog { get; set; }
        /// <summary>
        /// 多人实训：当前房间的所有成员ID及其扮演的岗位；
        /// </summary>
        public List<DP<int, string>> MemberPosts { get; set; }


        public List<TrainErrorStat> GetErrorStat()
        {
            if (OperationLog == null) return null;

            List<TrainErrorStat> reList = new List<TrainErrorStat>();
            int stepIndex = 0;
            foreach (var step in OperationLog)
            {
                string[] stepIdAndLogsArr = step.Split(new string[] { "|&|" }, StringSplitOptions.None); //步骤和操作
                if (stepIdAndLogsArr.Length == 2)
                {
                    string stepLog = stepIdAndLogsArr[1];
                    if (stepLog.Trim() == "") continue;

                    string[] opArr = stepLog.Split(new string[] { "||" }, StringSplitOptions.None);
                    for (int i = 0; i < opArr.Length; i++)
                    {
                        string opIdAndLog = opArr[i];
                        string[] op = opIdAndLog.Split(new string[] { "|&" }, StringSplitOptions.None);

                        //int opId = int.Parse(op[0]);//这里不根据这个值获取，根据索引值获取
                        string opLog = op[1].Trim();
                        if (opLog == "") continue;
                        string[] opLogArr = opLog.Split(new string[] { "&&" }, StringSplitOptions.None);
                        TrainErrorStat tes = new TrainErrorStat { projectId = ProjectId, taskId = TaskId, stepIndex = stepIndex, opIndex = i, total = 1 };
                        foreach (var item in opLogArr)
                        {
                            if (item.Contains("错误"))
                            {
                                tes.errors = 1;
                                break;
                            }
                        }
                        reList.Add(tes);
                    }
                }
                stepIndex++;
            }
            return reList;

        }

    }
}
